package com.youyi.yychosesdk.utils.system;

import android.app.Activity;
import android.content.Context;
import android.os.Build;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import java.lang.reflect.Method;

public class SystemUtils {
    private static SystemUtils instance;
    private Boolean hasNavigation = null;

    private SystemUtils() {
    }

    public static SystemUtils getInstance() {
        if (instance == null) {
            synchronized (SystemUtils.class) {
                if (instance == null) {
                    instance = new SystemUtils();
                }
            }
        }
        return instance;
    }

    public boolean hasNavigationBar(Activity activity) {
        if (this.hasNavigation == null) {
            boolean z = true;
            if (Build.VERSION.SDK_INT >= 17) {
                int i = activity.getResources().getDisplayMetrics().heightPixels;
                DisplayMetrics displayMetrics = new DisplayMetrics();
                activity.getWindowManager().getDefaultDisplay().getRealMetrics(displayMetrics);
                if (displayMetrics.heightPixels - i <= 0) {
                    z = false;
                }
                this.hasNavigation = Boolean.valueOf(z);
            } else {
                this.hasNavigation = true;
            }
        }
        return this.hasNavigation.booleanValue();
    }

    public void systemUiInit(Activity activity, View view) {
        if (!hasNavigationBar(activity)) {
            activity.getWindow().addFlags(256);
            activity.getWindow().addFlags(512);
        } else if (Build.VERSION.SDK_INT >= 16) {
            view.setSystemUiVisibility(512);
        }
    }

    private void hideStatusBar(Activity activity) {
        WindowManager.LayoutParams attributes = activity.getWindow().getAttributes();
        attributes.flags |= 1024;
        activity.getWindow().setAttributes(attributes);
    }

    private void showStatusBar(Activity activity) {
        WindowManager.LayoutParams attributes = activity.getWindow().getAttributes();
        attributes.flags &= -1025;
        activity.getWindow().setAttributes(attributes);
    }

    public void systemUiHide(Activity activity, View view) {
        if (!hasNavigationBar(activity)) {
            hideStatusBar(activity);
        } else if (Build.VERSION.SDK_INT >= 19) {
            view.setSystemUiVisibility(4871);
        } else if (Build.VERSION.SDK_INT >= 16) {
            view.setSystemUiVisibility(775);
        }
    }

    public void systemUiShow(Activity activity, View view) {
        if (!hasNavigationBar(activity)) {
            showStatusBar(activity);
        } else if (Build.VERSION.SDK_INT >= 16) {
            view.setSystemUiVisibility(1536);
        }
    }

    public int getStatusBarHeight(Context context) {
        int identifier = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
        if (identifier > 0) {
            return context.getResources().getDimensionPixelSize(identifier);
        }
        return (int) ((context.getResources().getDisplayMetrics().density * 23.0f) + 0.5f);
    }

    public void setStatusDark(Activity activity, boolean z) {
        if (isFlymeV4OrAbove()) {
            MeiZuStatusUtils.setStatusBarDarkIcon(activity, z);
        } else if (isMIUIV6OrAbove()) {
            setStatusTextBlackMi(activity, z);
        } else {
            setStatusTextBlackAndroid(activity, z);
        }
    }

    private void setStatusTextBlackMi(Activity activity, boolean z) {
        Class<?> cls = activity.getWindow().getClass();
        try {
            Class<?> cls2 = Class.forName("android.view.MiuiWindowManager$LayoutParams");
            int i = cls2.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE").getInt(cls2);
            Method method = cls.getMethod("setExtraFlags", Integer.TYPE, Integer.TYPE);
            Window window = activity.getWindow();
            Object[] objArr = new Object[2];
            objArr[0] = Integer.valueOf(z ? i : 0);
            objArr[1] = Integer.valueOf(i);
            method.invoke(window, objArr);
        } catch (Exception e) {
            e.printStackTrace();
        }
        setStatusTextBlackAndroid(activity, z);
    }

    private void setStatusTextBlackAndroid(Activity activity, boolean z) {
        if (Build.VERSION.SDK_INT >= 23) {
            Window window = activity.getWindow();
            if (z) {
                window.addFlags(Integer.MIN_VALUE);
                window.clearFlags(67108864);
                window.getDecorView().setSystemUiVisibility(8192);
                return;
            }
            window.getDecorView().setSystemUiVisibility(window.getDecorView().getSystemUiVisibility() & -8193);
        }
    }

    private boolean isFlymeV4OrAbove() {
        String str = Build.DISPLAY;
        if (!TextUtils.isEmpty(str) && str.contains("Flyme")) {
            for (String str2 : str.split(" ")) {
                if (str2.matches("^[4-9]\\.(\\d+\\.)+\\S*")) {
                    return true;
                }
            }
        }
        return false;
    }

    private boolean isMIUIV6OrAbove() {
        String systemProperty = getSystemProperty("ro.miui.ui.version.code");
        if (TextUtils.isEmpty(systemProperty)) {
            return false;
        }
        try {
            return Integer.parseInt(systemProperty) >= 4;
        } catch (Exception unused) {
            return false;
        }
    }

    private boolean isAndroidMOrAbove() {
        return Build.VERSION.SDK_INT >= 23;
    }

    /* JADX WARNING: Removed duplicated region for block: B:14:0x003d A[SYNTHETIC, Splitter:B:14:0x003d] */
    /* JADX WARNING: Removed duplicated region for block: B:21:0x0044 A[SYNTHETIC, Splitter:B:21:0x0044] */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    private String getSystemProperty(String r5) {
        /*
            r4 = this;
            r0 = 0
            java.lang.Runtime r1 = java.lang.Runtime.getRuntime()     // Catch:{ IOException -> 0x0041, all -> 0x003a }
            java.lang.StringBuilder r2 = new java.lang.StringBuilder     // Catch:{ IOException -> 0x0041, all -> 0x003a }
            r2.<init>()     // Catch:{ IOException -> 0x0041, all -> 0x003a }
            java.lang.String r3 = "getprop "
            r2.append(r3)     // Catch:{ IOException -> 0x0041, all -> 0x003a }
            r2.append(r5)     // Catch:{ IOException -> 0x0041, all -> 0x003a }
            java.lang.String r5 = r2.toString()     // Catch:{ IOException -> 0x0041, all -> 0x003a }
            java.lang.Process r5 = r1.exec(r5)     // Catch:{ IOException -> 0x0041, all -> 0x003a }
            java.io.BufferedReader r1 = new java.io.BufferedReader     // Catch:{ IOException -> 0x0041, all -> 0x003a }
            java.io.InputStreamReader r2 = new java.io.InputStreamReader     // Catch:{ IOException -> 0x0041, all -> 0x003a }
            java.io.InputStream r5 = r5.getInputStream()     // Catch:{ IOException -> 0x0041, all -> 0x003a }
            r2.<init>(r5)     // Catch:{ IOException -> 0x0041, all -> 0x003a }
            r5 = 1024(0x400, float:1.435E-42)
            r1.<init>(r2, r5)     // Catch:{ IOException -> 0x0041, all -> 0x003a }
            java.lang.String r5 = r1.readLine()     // Catch:{ IOException -> 0x0038, all -> 0x0035 }
            r1.close()     // Catch:{ IOException -> 0x0038, all -> 0x0035 }
            r1.close()     // Catch:{ IOException -> 0x0034 }
        L_0x0034:
            return r5
        L_0x0035:
            r5 = move-exception
            r0 = r1
            goto L_0x003b
        L_0x0038:
            goto L_0x0042
        L_0x003a:
            r5 = move-exception
        L_0x003b:
            if (r0 == 0) goto L_0x0040
            r0.close()     // Catch:{ IOException -> 0x0040 }
        L_0x0040:
            throw r5
        L_0x0041:
            r1 = r0
        L_0x0042:
            if (r1 == 0) goto L_0x0047
            r1.close()     // Catch:{ IOException -> 0x0047 }
        L_0x0047:
            return r0
        */
        throw new UnsupportedOperationException("Method not decompiled: com.youyi.yychosesdk.utils.system.SystemUtils.getSystemProperty(java.lang.String):java.lang.String");
    }
}
